*** Creates estimates for Table A1 and Figures 2 from the 1992-96 panel data

*** Creation of 56/60, 72/76, 92/96, and 00/04 data files documented in dataverse for 2017 AJPS - Polarization and the Decline of the American Floating Voter - dataverse link: https://doi.org/10.7910/DVN/4FCVUR



clear
use "data/amelia90s.dta" 
merge 1:1 id using data/observed90s.dta, keepusing(pref92 pref96)
drop _merge
gen ID1992 = id-920000

tab pid92
tab pid96

gen partyidswitch = 0 if pid92!=. & pid96!=.
replace partyidswitch = 1 if pid92<=2 & pid96>=4 & pid96<7
replace partyidswitch = 1 if pid92>=4 & pid92<7 & pid96<=2
proportion partyidswitch [pw=weight]


gen prefswitch = 0 if pref92!=. & pref96!=.
replace prefswitch = 1 if pref92==1 & pref96==2
replace prefswitch = 1 if pref92==2 & pref96==1
proportion prefswitch [pw=weight]

drop partyidswitch prefswitch

gen demvreppref92 = 1 if pref92==1
replace demvreppref92 = 0 if pref92==2
gen demvreppref96 = 1 if pref96==1
replace demvreppref96 = 0 if pref96==2

gen prefswitch = 0 if demvreppref92!=. & demvreppref96!=.
replace prefswitch = 1 if demvreppref92!=demvreppref96 & prefswitch!=.

proportion prefswitch [pw=weight]

drop prefswitch


desc

mi set mlong

misstable summarize

mi register imputed education female black catholic income92 precooperate92 prepolsoph92 intel92 suspicious92 interest92 sincerity92 pid92 reptherm92 demtherm92 demcandtherm_pre92 repcandtherm_pre92 blackstherm*92 perottherm_pre92 pid93 pid94 pid96 presapprove92 presapprove94 presapprove96 repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 prepref92 prepref96 pref92 pref96


mi impute chained (logit, omit( suspicious92 precooperate92 prepolsoph92 intel92 sincerity92 interest92 i.pid92  presapprove92 perottherm_pre92  reptherm92 demtherm92 demcandtherm_pre92 repcandtherm_pre92 income92 i.pid94 i.pid93 presapprove94 i.pid96 presapprove96 i.prepref96 i.pref92 i.pref96  repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 ) ) catholic black (ologit, ascontinuous omit( i.pid94 i.pid93 presapprove94 i.pid96 presapprove96 i.prepref96 i.pref92 i.pref96 perottherm_pre92  reptherm92 demtherm92  demcandtherm_pre92 repcandtherm_pre92  repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 )) income92 precooperate92 prepolsoph92 intel92 suspicious92 interest92 sincerity92  presapprove92 education (ologit, omit( i.pid94 i.pid93 presapprove94 i.pid96 presapprove96 i.prepref96 i.pref92 i.pref96  demcandtherm_pre92 repcandtherm_pre92  repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96  )) pid92 (truncreg, ll(0) ul(97) omit( i.pid94 i.pid93 presapprove94 i.pid96 presapprove96 i.prepref96 i.pref96 i.pref92  repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 )) reptherm92 demtherm92 blackstherm*92 perottherm_pre92  demcandtherm_pre92 repcandtherm_pre92 (mlogit, augment omit( i.pid94 i.pid93 presapprove94 i.pid96 presapprove96 i.prepref96 i.pref92 i.pref96 reptherm92 demtherm92  repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 )) prepref92 (mlogit, augment omit(i.pid92 i.pid94 i.pid93 presapprove94 i.pid96 presapprove96 i.prepref96 i.pref96  reptherm92 demtherm92  repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 )) pref92 (ologit, omit(i.pid96 presapprove96 i.prepref96 i.pref96  demcandtherm_pre92 repcandtherm_pre92  repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 )) pid93 (ologit, omit(i.pid96 presapprove96 i.prepref92 i.prepref96 i.pref96  demcandtherm_pre92 repcandtherm_pre92  repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 )) pid94  (ologit, ascontinuous omit(i.pid92 i.pid93 i.prepref92 i.prepref96 presapprove96 i.pid96 i.pref96 reptherm92 demtherm92  repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 )) presapprove94 (truncreg, ll(0) ul(100) omit(i.pid92 i.pid94 i.pid93 presapprove94 i.pref96 i.pref92)) repcandtherm_pre96 demcandtherm_pre96 perottherm_pre96 (ologit, omit(i.prepref92 i.prepref96 i.pid93 i.pref96 demcandtherm_pre92 repcandtherm_pre92 perottherm_pre92)) pid96 (ologit, ascontinuous omit(i.pid92 i.pid93 i.pid94 i.prepref92 i.prepref96 i.pref96 reptherm92 demtherm92)) presapprove96 (mlogit, augment omit(i.prepref92 i.pid93 i.pid94 reptherm92 demtherm92 repcandtherm_pre92 demcandtherm_pre92 perottherm_pre92)) prepref96 (mlogit, augment omit(i.pid92 i.pid93 i.pid94 suspicious92 precooperate92 prepolsoph92 intel92 sincerity92 interest92 i.catholic blackstherm92 presapprove92 reptherm92 demtherm92 repcandtherm_pre92 demcandtherm_pre92 perottherm_pre92 income92 presapprove94 i.prepref92 i.pref92 female south midwest west presapprove96)) pref96 = female south midwest west, add(40) burnin(20) chaindots rseed(54321)

mi estimate: proportion pid92 [pw=weight]
mi estimate: proportion pid96 [pw=weight]

mi passive: gen partyidswitch = 0 if pid92!=. & pid96!=.
mi passive: replace partyidswitch = 1 if pid92<=2 & pid96>=4 & pid96<7
mi passive: replace partyidswitch = 1 if pid92>=4 & pid92<7 & pid96<=2

mi estimate: proportion partyidswitch [pw=weight]

mi estimate, saving(mi_mlogit92, replace): mlogit pref92 i.pid92  demcandtherm_pre92 repcandtherm_pre92 perottherm_pre92 presapprove92 i.prepref92 age female black catholic, base(1) 
mi predict xb92_1_mi using mi_mlogit92
mi predict xb92_2_mi using mi_mlogit92, equation(#2)
mi predict xb92_3_mi using mi_mlogit92, equation(#3)
mi xeq 0: summarize xb92_1_mi xb92_2_mi xb92_3_mi

mi passive: gen demvrepphat92 = 1/(1+exp(xb92_2_mi))
mi estimate: mean demvrepphat92
mi passive: gen simdem92 = uniform()<=demvrepphat92
mi passive: gen demvrepchoice92 = demvreppref92
mi passive: replace demvrepchoice92 = simdem92 if demvrepchoice92==.

mi estimate, saving(mi_mlogit96, replace): mlogit pref96 i.pid96 demcandtherm_pre96 repcandtherm_pre96 perottherm_pre96 presapprove96 i.prepref96 age female black catholic, base(1) 

mi predict xb96_1_mi using mi_mlogit96
mi predict xb96_2_mi using mi_mlogit96, equation(#2)
mi predict xb96_3_mi using mi_mlogit96, equation(#3)
mi xeq 0: summarize xb96_1_mi xb96_2_mi xb96_3_mi

mi passive: gen demvrepphat96 = 1/(1+exp(xb96_2_mi))
mi estimate: mean demvrepphat96
mi passive: gen simdem96 = uniform()<=demvrepphat96
mi passive: gen demvrepchoice96 = demvreppref96
mi passive: replace demvrepchoice96 = simdem96 if demvrepchoice96==.

mi estimate: proportion demvrepchoice92 demvrepchoice96 [pw=weight]

mi passive: gen supportswitch = 0 if pref92!=. & pref96!=.
mi passive: replace supportswitch = 1 if pref92==1 & pref96==2
mi passive: replace supportswitch = 1 if pref92==2 & pref96==1

mi estimate: proportion supportswitch [pw=weight]

drop supportswitch

****************
** no 3rd party
****************

** make sure imputed values are consistent

mi passive: gen supportswitch = 0 if demvrepchoice92!=. & demvrepchoice96!=.
mi passive: replace supportswitch = 1 if demvrepchoice92!=demvrepchoice96
mi estimate: proportion supportswitch [pw=weight]



